#include "pipe_send_buff.h"

PipeSendBuff::PipeSendBuff(const char *str): Buff() {
	length = strlen(str);
	remain = length;
	buff = new char[length + 10];
	strcpy(buff, str);
	status = 0;
	index = 0;
}			 

PipeSendBuff::~PipeSendBuff() {
	delete[] buff;
}

ssize_t PipeSendBuff::send_data(int fd) {
	ssize_t tot = 0;
	while (remain > 0) {
		ssize_t n = write(fd, buff+index, remain);
		if (n == -1) return n;
		tot += n;
		index += n;
		remain -= n;
	}
	status = 1;
	return tot;
}

bool PipeSendBuff::finish() {
	return status >= 1;
}
